﻿<p> <code>chgrp</code> 是 <code>change group</code>的简写， 主要的功能是改变一个档案的所属群组。</p>

<p><strong>1. 命令格式</strong></p>
<p><code>chgrp [OPTION]... GROUP FILE...</code><br />
  or:  <code>chgrp [OPTION]... --reference=RFILE FILE...</code></p>

<p><strong>2. 命令功能</strong></p>
<p>Change the group of each FILE to GROUP.<br />
With --reference, change the group of each FILE to that of RFILE.</p>

<p><strong>3. 命令参数</strong></p>
<p>
    <code class="m-r-md">-R, --recursive</code><span class="label label-danger">常用</span>进行递归的持续变更，即连同子目录下的所有档案、目录都变更成这个群组。<br />
    <small>operate on files and directories recursively</small><br />
</p>

<p><strong>4. Example</strong></p>
<ul>
    <li><code>chgrp staff /u</code>:Change the group of /u to "staff".</li>
    <li><code>chgrp -hR staff /u</code>:Change the group of /u and subfiles to "staff".</li>
</ul>


<p><strong>5. 命令实例</strong></p>
<ul>
    <li>更改test.txt档案的群组为root:
        <pre><code>[root@localhost wangyuchuan]# ll
total 0
-rw-rw-r--. 1 wangyuchuan wangyuchuan 0 Jan 10 19:48 test.txt
[root@localhost wangyuchuan]# chgrp root test.txt 
[root@localhost wangyuchuan]# ll
total 0
-rw-rw-r--. 1 wangyuchuan root 0 Jan 10 19:48 test.txt</code></pre>
    </li>
    <li>更改test.txt档案的群组为test:
        <pre><code>[root@localhost wangyuchuan]# chgrp test test.txt 
chgrp: invalid group: `test'</code></pre>
    从结果可以看到，要被改变的组名必须要在/etc/group 档案内存在
才行，否则就会显示错误！
    </li>
</ul>